/**
 * 
 */
package IC.Analyzer;

import IC.AST.ASTNode;
import IC.AST.DefaultVisitor;

/**
 * A default checker that supports error recovery
 *
 */
public class Checker<D, U> extends DefaultVisitor<D, U> {
	private boolean recoverErrors = false;
	private boolean errorFlag = false;

	public void error(ASTNode node, String message) throws Exception {
		Exception e = new SemanticError(node,message);
		if (! recoverErrors) 
			throw e;
		else
			System.err.println(e.getMessage());
		errorFlag = true;
	}

	public void error(ASTNode node, String message, Object[] values) throws Exception {
		String str = String.format(message, values);
		error(node, str);
	}

	public void recoverErrors() {
		recoverErrors = true;
	}

	public boolean hadError() {
		return errorFlag;
	}
}
